package com.simple.datax.dao.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.simple.base.dao.BaseDAO;
import com.simple.datax.dao.IDataxFlowActorsTemplateDAO;
import com.simple.datax.vo.DataxFlowActorsTemplateIdVO;
import com.simple.datax.vo.DataxFlowActorsTemplateVO;

@Repository("dataxFlowActorsTemplateDAO")
public class DataxFlowActorsTemplateDAOImpl extends BaseDAO implements
		IDataxFlowActorsTemplateDAO {

	@Override
	public DataxFlowActorsTemplateVO findById(DataxFlowActorsTemplateIdVO id) {
		return super.get(DataxFlowActorsTemplateVO.class, id);
	}

	@Override
	public void saveOrUpdate(DataxFlowActorsTemplateVO dataxFlowActorsTemplateVO ) {
		super.saveOrUpdate(dataxFlowActorsTemplateVO);
	}

	@Override
	public void update(DataxFlowActorsTemplateVO dataxFlowActorsTemplateVO) {
		super.saveOrUpdate(dataxFlowActorsTemplateVO);
	}

	@Override
	public List<DataxFlowActorsTemplateVO> findAll() {
		return super.query(DataxFlowActorsTemplateVO.class);
	}

	@Override
	public void delete(DataxFlowActorsTemplateVO dataxFlowActorsTemplateVO) {
		super.delete(dataxFlowActorsTemplateVO);
	}

	@Override
	public void delete(DataxFlowActorsTemplateIdVO id) {
		super.delete(DataxFlowActorsTemplateVO.class,id);
	}

	@Override
	public Integer generateId() {
		final List<?> list =  getSession().createSQLQuery("select seq_flow_node_id.nextval from dual").list();
		return ((BigDecimal)list.get(0)).intValue();
	}

	@Override
	public List<DataxFlowActorsTemplateVO> findByFlowTempId(String flowTemplateId) {
		 String hql="from DataxFlowActorsTemplateVO d where 1>0 and d.id.flowTemplateId=? order by d.id.actorNo asc ";
		return super.query(hql, flowTemplateId);
	}

	@Override
	public void addBatch(
			List<DataxFlowActorsTemplateVO> listDataxFlowActorsTemplateVO) {
		super.saveOrUpdate(listDataxFlowActorsTemplateVO);
	}

	@Override
	public void deleteByFlowTemplateId(String flowTemplateId) {
		String hql="delete from DataxFlowActorsTemplateVO d where  d.id.flowTemplateId=? ";
		final List<String> paramList = new ArrayList<String>();
		paramList.add(flowTemplateId);
		super.executeUpdate(hql, paramList);
	}

}
